package com.example.booksshop.controller;
import com.example.booksshop.entity.Book;
import com.example.booksshop.entity.BookCategory;
import com.example.booksshop.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author xuan 2021/9/14
 */
@Controller
public class BookController {
    @Autowired
    BookService bookService;

    @RequestMapping(value = "/bookInsert", method = {RequestMethod.POST})
    @ResponseBody
    public String bookInsert(@RequestParam String bookname,@RequestParam String author,@RequestParam Integer cid){
        bookService.bookInsert(bookname, author, cid);
        return "success";
    }

    @RequestMapping(value = "/showBooks", method = {RequestMethod.GET})
    @ResponseBody
    public List<BookCategory> showBooks() {
        return bookService.showBooks();
    }

    @RequestMapping(value = "/selectBook", method = {RequestMethod.POST})
    @ResponseBody
    public BookCategory book(@RequestParam String bookname) {
        return bookService.selectBook(bookname);
    }

    @RequestMapping(value = "/deleteBook", method = {RequestMethod.POST})
    @ResponseBody
    public String deleteBook(@RequestParam String bookname) {
        bookService.deleteBook(bookname);
        return "success";
    }

    @RequestMapping(value = "/categoryBook", method = {RequestMethod.POST})
    @ResponseBody
    public List<BookCategory> categoryBook(@RequestParam String category) {
        return bookService.categoryBook(category);
    }

    @RequestMapping(value = "/updateBook", method = {RequestMethod.POST})
    @ResponseBody
    public String updateBook(@RequestBody Book book) {
        bookService.updateBook(book);
        return "success";
    }
}
